package 接口.接口使用实例;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 姚东名
 * Date: 2024-06-18
 * Time: 22:10
 */
//让我们的 Student 类实现 Comparable 接口, 并实现其中的 compareTo 方法
public class Student1 implements Comparable {
    private String name;
    private int score;

    public Student1(String name, int score) {
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student1{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Object o) {
        Student1 student1 = (Student1)o;

        if(this.score > student1.score) {
            return -1;
        } else if (this.score < student1.score) {
            return 1;
        } else {
            return 0;
        }
    }
}
